package com.rjpacket.chileme.app.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.widget.ImageView;
import com.rjpacket.chileme.app.tasks.ImageLoader;

/**
 * Created by aaa on 15-3-11.
 */
public class MyImageLoadMethod {
    private MyImageLoadMethod(){

    }

    public static void load(String thumb,ImageView imageView){
        if(thumb != null && thumb.length() > 0){
            imageView.setTag(thumb);

            ImageCache imageCache = ImageCache.getInstance();

            Bitmap bitmap = imageCache.getImage(thumb);

            if(bitmap != null){
                imageView.setImageBitmap(bitmap);
            }else{
                FileCache fileCache = FileCache.getInstance();

                byte[] bytes = fileCache.getContent(thumb);

                if(bytes != null && bytes.length > 0){
                    Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                    imageView.setImageBitmap(bmp);

                    imageCache.putImage(thumb,bmp);
                }else{
                    //网络加载
                    ImageLoader task = new ImageLoader(imageView);
                    task.execute(thumb);
                }
            }
        }
    }
}
